﻿using AutoMapper;
using Enferno.Public.Web.Mappers.Resolvers;
using Enferno.Public.Web.Models;
using Enferno.Public.Web.ViewModels;
using Enferno.StormApiClient.Products;

namespace Enferno.Public.Web.Mappers.ProductProfiles
{
    public class VariantModelToVariantViewModelProfile : VariantBaseModelToVariantBaseViewModelProfile<
        VariantModel,
        OnHandStatusModel,
        PriceModel,
        ProductFileModel,
        ParametricModel,
        ParametricValueModel,
        VariantViewModel,
        FileViewModel,
        ParametricViewModel,
        ParametricValueViewModel>
    {
        
    }

    public class VariantBaseModelToVariantBaseViewModelProfile<
        TVariantModel, 
        TOnHandStatusModel,
        TPriceModel,
        TProductFileModel,
        TParametricModel,
        TParametricValueModel,
        TVariantViewModel,
        TFileViewModel,
        TParametricViewModel,
        TParametricValueViewModel> : Profile
        where TVariantModel: VariantBaseModel<TOnHandStatusModel, TPriceModel, TProductFileModel, TParametricModel, TParametricValueModel>
        where TOnHandStatusModel: OnHandStatusModel
        where TPriceModel: PriceModel
        where TProductFileModel: ProductFileModel
        where TParametricModel: ParametricBaseModel<TParametricValueModel>
        where TParametricValueModel: ParametricValueModel
        where TVariantViewModel: VariantBaseViewModel<TFileViewModel, TParametricViewModel, TParametricValueViewModel>
        where TFileViewModel: FileViewModel
        where TParametricViewModel: ParametricBaseViewModel<TParametricValueViewModel>
        where TParametricValueViewModel: ParametricValueViewModel

    {
        protected override void Configure()
        {
            Mapper.CreateMap<TVariantModel, TVariantViewModel>()
                .ForMember(to => to.OnHandStatusText1, opts => opts.MapFrom(from => from.OnHandStatus.Text1))
                .ForMember(to => to.OnHandStatusText2, opts => opts.MapFrom(from => from.OnHandStatus.Text2))
                .ForMember(to => to.OnHandStatus, opts => opts.MapFrom(from => from.OnHandStatus.Status))
                .ForMember(to => to.OnHandStatusCount, opts => opts.MapFrom(from => from.OnHandStatus.Count))
                .ForMember(to => to.DisplayPrice, opts => opts.MapFrom(from => from.Price.Display))
                .ForMember(to => to.CatalogPrice, opts => opts.MapFrom(from => from.Price.Catalog))
                .ForMember(to => to.VatRate, opts => opts.MapFrom(from => from.Price.VatRate))
                .ForMember(to => to.PriceListId, opts => opts.MapFrom(from => from.Price.PricelistId));
        }

        public override string ProfileName
        {
            get { return GetType().Name; }
        }
    }
}
